package com.yao.club.mapper;

import com.yao.club.entity.UserEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user_profile where cellphone =#{cellphone}")
    UserEntity select(@Param("cellphone") String cellphone);

    @Select("select * from user_profile where nickname like CONCAT('%',#{nickname},'%')")
    List<UserEntity> selectByNickName(@Param("nickname") String nickname);

    @Select("select * from user_profile where member_id =#{memberId}")
    UserEntity getUserByMemberId(@Param("memberId") String memberId);


    @Select("select * from user_profile where cellphone =#{cellphone} and password = #{password}")
    UserEntity login(@Param("cellphone") String cellphone,@Param("password") String password);

    @Select("select max(sy_user_id) from user_profile")
    long getMaxSysUserId();

    @Insert("insert into user_profile(member_id,sy_user_id,username,nickname,cellphone,avatar_id) values(null,#{sys_user_id},#{username},#{nickname},#{cellphone},2)")
    int insert(@Param("sys_user_id") long sys_user_id, @Param("username") String username, @Param("nickname") String nickname, @Param("cellphone") String cellphone);

    @Update("update user_profile set password = #{password},has_password = 1 where  cellphone=#{cellphone} ")
    int setNewPwd(@Param("password") String password, @Param("cellphone") String cellphone);

    @Update("update user_profile set follow_count = follow_count+1 where  member_id=#{member_id} ")
    int incrementFollowCount(@Param("member_id") String member_id);

    @Update("update user_profile set follow_count = follow_count-1 where  member_id=#{member_id} ")
    int unIncrementFollowCount(@Param("member_id") String member_id);

    @Update("update user_profile set fans_count = fans_count+1 where  member_id=#{member_id} ")
    int incrementFansCount(@Param("member_id") String member_id);

    @Update("update user_profile set fans_count = fans_count-1 where  member_id=#{member_id} ")
    int unIncrementFansCount(@Param("member_id") String member_id);

    @Update("update user_profile set friends_count = friends_count+1 where  member_id=#{member_id} ")
    int incrementFriendsCount(@Param("member_id") String member_id);

    @Update("update user_profile set friends_count = friends_count-1 where  member_id=#{member_id} ")
    int unIncrementFriendsCount(@Param("member_id") String member_id);

}
